﻿using Infra.Utils.ExpressionTree;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DAL.Database.Db
{
    public interface IRepository<T> : IDisposable
    {
        int Count { get; }

        IEnumerable<T> Get { get; }
        IQueryable<T> All();
        IEnumerable<T> Filter(T entity, IQueryManager querymanager);
        IQueryable<T> Filter(Expression<Func<T, bool>> predicate);
        IQueryable<T> Filter(Expression<Func<T, bool>> filter, out int total, int index = 0, int size = 50);
        IEnumerable<T> Filter(T entity, IQueryManager querymanager, out int total, int index = 0, int size = 50);
        bool Contains(Expression<Func<T, bool>> predicate);

        T Find(T entity);
        T Find(params object[] keys);
        T Find(Expression<Func<T, bool>> predicate);

        T Insert(T entity);

        void Delete(T entity);
        void Delete(Expression<Func<T, bool>> predicate);

        void Update(T entity);
        void Update(Expression<Func<T, bool>> predicate, Action<T> action);

        T InsertIfNotExist(T entity);
        T InsertIfNotExist(Expression<Func<T, bool>> predicate, T entity);

        T InsertOrUpdate(Expression<Func<T, bool>> predicate, T entity, Action<T> action);

        void Restore(T entity);

        void SaveChanges();
    }
}
